package com.yishe.controller.wx.userinfo;

import com.yishe.biz.wx.WxUserInfoBiz;
import com.yishe.config.ObjectRestResponse;
import com.yishe.entites.mysql.WxUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/18 14:51
 * @description: 用户相关的操作Action
 * @package com.yishe.controller.wx
 * @className WxUserBiz
 */
@RestController
@Slf4j
@RequestMapping(value = "/wx/userinfo")
public class WxUserInfoController {

    @Resource
    private WxUserInfoBiz wxUserInfoBiz;
    /**
     * 获取用户会员信息
     */
    @PostMapping(value = "getUserMemberInfo")
    public ObjectRestResponse getUserMemberInfo(@RequestBody Map<String , String> params){
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        if (params.isEmpty()){
            objectRestResponse.setErrorMsg("参数有误！");
            return objectRestResponse;
        }
        try {
            objectRestResponse.setData(wxUserInfoBiz.getUserMemberByOpenid(params));
        } catch (Exception e) {
            e.printStackTrace();
            objectRestResponse.setErrorMsg("查询用户会员等级信息有误");
        }
        return objectRestResponse;
    }
    /**
     * 获取用户会员信息
     */
    @PostMapping(value = "getUserInfo")
    public ObjectRestResponse getUserInfo(@RequestBody Map<String , String> params){
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        if (params.isEmpty()){
            objectRestResponse.setErrorMsg("参数有误！");
            return objectRestResponse;
        }
        try {
            objectRestResponse.setData(wxUserInfoBiz.getUserInfo(params));
        } catch (Exception e) {
            e.printStackTrace();
            objectRestResponse.setErrorMsg("查询用户会员等级信息有误");
        }
        return objectRestResponse;
    }/**
     * 获取用户会员信息
     */
    @PostMapping(value = "saveUserInfo")
    public ObjectRestResponse saveUserInfo(@RequestBody WxUser wxUser){
        ObjectRestResponse objectRestResponse = new ObjectRestResponse();
        try {
            wxUserInfoBiz.saveUserInfo(wxUser);
        } catch (Exception e) {
            log.error("更新用戶西悉尼失敗！",e);
            objectRestResponse.setErrorMsg("查询用户会员等级信息有误");
        }
        return objectRestResponse;
    }
}
